﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CCH.DAO;

public partial class _20_2001 : System.Web.UI.Page
{
    NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

    protected void Page_Load(object sender, EventArgs e)
    {
        //取回功能編號
        string sfu_type = Request["type"];
        int sfu_no = new sysfunctionDAO().Get_pathNO(2001, sfu_type);
        ((MasterPage)this.Master).Create_menu(sfu_no);

        if (!this.IsPostBack)
        {
            this.ObjectDataSource1.SelectParameters["sfu_no"].DefaultValue = sfu_type;
            this.DropDownList1.Items.Insert(0, new ListItem("全部", "0"));
            this.GridView1.DataBind();

        }

        //判斷來自JS 使用_doPostBack(updatePanel,"") 的情況
        if (Request["__EVENTTARGET"] == this.UpdatePanel1.ClientID && String.IsNullOrEmpty(Request["__EVENTARGUMENT"]))
        {

            //logger.Debug("updatePanel sfu_type=" + sfu_type);
            //this.ObjectDataSource1.SelectParameters["type_class"].DefaultValue = sfu_type;
            this.GridView1.DataBind();
        }

    }

    #region 資料欄位轉換
    protected String Get_classificationName(object cla_no)
    {
        int clano = Convert.ToInt32(cla_no);

        return new classificationDAO().Get_classificaitonName(clano);
    }

    protected String Get_peopleName(object peo_uid)
    {
        int uid = Convert.ToInt32(peo_uid);

        return new peopleDAO().Get_peopleName(uid);
    }

    protected String Get_DateTime(object datetime)
    {
        return ((DateTime)datetime).ConvertToROC();
    }

    #endregion

    protected String Get_url(object mes_no)
    {
        return string.Format("2001-1.aspx?mode=edit&ID={0}&type={1}&modal=true&TB_iframe=true&width=800&height=500", mes_no.ToString(), Request["type"]);
    }

    protected String Get_url_new()
    {
        return string.Format("2001-1.aspx?mode=new&type={0}&modal=true&TB_iframe=true&width=800&height=510", Request["type"]);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int rowIndex = System.Convert.ToInt32(e.CommandArgument);
        int id = System.Convert.ToInt32(this.GridView1.DataKeys[rowIndex].Value.ToString());

        //停用
        if (e.CommandName.Equals("disable"))
        {
            new messageDAO().Delete_message(id, new SessionObject().SessionUserID);
            //this.ObjectDataSource1.SelectParameters["type_class"].DefaultValue = Request["type"];
            this.GridView1.DataBind();
        }

    }
}